package com.dmwork.service.customer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dmwork.service.customer.entity.FollowGroup;
import com.dmwork.service.customer.entity.vo.FollowGroupInfoVo;
import com.dmwork.service.customer.mapper.FollowGroupMapper;
import com.dmwork.service.customer.service.FollowGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 李天
 * @since 2021-03-13
 */
@Transactional
@Service
public class FollowGroupServiceImpl extends ServiceImpl<FollowGroupMapper, FollowGroup> implements FollowGroupService {

    @Override
    public List<FollowGroupInfoVo> getFollowGroupList(String customerId) {
        QueryWrapper<FollowGroup> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("customer_id", customerId)
                .or()
                .eq("id", FollowGroup.DEFAULT_GROUP_ID)
                .or()
                .eq("id", FollowGroup.SPECIAL_FOLLOW_ID);
        List<FollowGroup> followGroupList = baseMapper.selectList(queryWrapper);
        //数据组装
        List<FollowGroupInfoVo> followGroupInfoVoList = new ArrayList<>();
        for (FollowGroup followGroup : followGroupList) {
            FollowGroupInfoVo infoVo = new FollowGroupInfoVo();
            infoVo.setId(followGroup.getId());
            infoVo.setGroupName(followGroup.getGroupName());
            followGroupInfoVoList.add(infoVo);
        }
        return followGroupInfoVoList;
    }
}
